/**
 * Copyright 2013 - Les petits mots
 */

function generateProgressPage() {
	var progressGame1Level1=0;
	var progressGame1Level2=0;
	var progressGame1Level3=0;
	var progressGame2Level1=0;
	var progressGame2Level2=0;
	var progressGame2Level3=0;
	var progressTotal=0;
	var countWords = idWords.length;	
	
	for(word in words) {
		if(getItemProgressionById(GAME_1,LEVEL_1,word)) {
			progressGame1Level1++;
			progressTotal++;
		}
		if(getItemProgressionById(GAME_1,LEVEL_2,word)) {
			progressGame1Level2++;
			progressTotal++;
		}
		if(getItemProgressionById(GAME_1,LEVEL_3,word)) {
			progressGame1Level3++;
			progressTotal++;
		}
		if(getItemProgressionById(GAME_2,LEVEL_1,word)) {
			progressGame2Level1++;
			progressTotal++;
		}
		if(getItemProgressionById(GAME_2,LEVEL_2,word)) {
			progressGame2Level2++;
			progressTotal++;
		}
		if(getItemProgressionById(GAME_2,LEVEL_3,word)) {
			progressGame2Level3++;
			progressTotal++;
		}
	}
	
	var test = progressTotal/(countWords*6);
	setProgressBar("#totalProgressBar",(progressTotal == 0 ? 0 : progressTotal/(countWords*6) )*100 );
	setProgressBar("#game1Level1ProgressBar",(progressGame1Level1 == 0 ? 0 : progressGame1Level1/countWords)*100 );
	setProgressBar("#game1Level2ProgressBar",(progressGame1Level2 == 0 ? 0 : progressGame1Level2/countWords)*100 );
	setProgressBar("#game1Level3ProgressBar",(progressGame1Level3 == 0 ? 0 : progressGame1Level3/countWords)*100 );
	setProgressBar("#game2Level1ProgressBar",(progressGame2Level1 == 0 ? 0 : progressGame2Level1/countWords)*100 );
	setProgressBar("#game2Level2ProgressBar",(progressGame2Level2 == 0 ? 0 : progressGame2Level2/countWords)*100 );
	setProgressBar("#game2Level3ProgressBar",(progressGame2Level3 == 0 ? 0 : progressGame2Level3/countWords)*100 );
}

function setProgressBar(id,val) {
	$(id)
	    .progressbar({ value: val })
	    .children('.ui-progressbar-value')
	    .html( (val!=100 ? val.toPrecision(2) : val) + '%' )
	    .css("display", "block");
}